<template>
  <el-dialog
    v-el-drag-dialog
    title="转派"
    :visible.sync="visible"
    width="400px"
    @closed="reset"
  >
    <el-form ref="dataForm" :rules="rules" :model="temp" label-position="right" label-width="110px">
      <el-form-item label="整改处理人:" prop="targetUserId">
        <el-select v-model="temp.targetUserId" clearable filterable :loading="$loadingPlugin.getOwnersList" style="width: 100%;" placeholder="请选择">
          <el-option
            v-for="item in ownersList"
            :key="item.userId"
            :label="item.userName"
            :value="item.userId"
          />
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="visible = false">
        取消
      </el-button>
      <el-button :loading="$loadingPlugin.submit" type="primary" @click="success">
        确定
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { queryRiskTrackTransfer, gasCheckUserQueryList } from '@/api'

  export default {
    name: 'transfer-order',
    data() {
      return {
        visible: false,
        ownersList: [],
        rows: [],
        temp: {
          targetUserId: ''
        },
        rules: {
          targetUserId: [{ required: true, message: '请选择整改处理人', trigger: 'change' }]
        }
      }
    },
    methods: {
      open(rows, org) {
        this.getOwnersList(org.orgSNNo)
        return new Promise(resolve => {
          this.resolve = resolve
          this.visible = true
          this.rows = rows
        })
      },
      // 查询处理人列表
      async getOwnersList(orgSNNo) {
        const res = await gasCheckUserQueryList({
          orgSNNo
        })
        this.ownersList = res.data
      },
      success() {
        this.$refs.dataForm.validate(valid => {
          if (!valid) return
          const params = {
            targetUserId: this.temp.targetUserId,
            codes: this.rows.map(item => item.traceCode).join(',')
          }
          this.submit(params)
        })
      },
      async submit(params) {
        await queryRiskTrackTransfer(params)
        this.resolve()
        this.visible = false
        this.$notify({
          title: '提示',
          message: '操作成功!',
          type: 'success',
          duration: 2000
        })
      },
      reset() {
        this.rows = []
        this.temp = {
          targetUserId: ''
        }
        this.$nextTick(() => {
          this.$refs.dataForm.clearValidate()
        })
      }
    }
  }
</script>

<style scoped>

</style>
